/******************************************************************************
* ++
* Author: BaoTD1
* Module Name : CButtonTopViewRight.h
*
* Description : Declares the CButtonTopViewRight 
*
*
* Mod. History :	06/Jun/2013		 - BaoTD1
*                             File first created
*                             CR# PROJECT
*
*
* --
******************************************************************************/

#include "stdafx.h"
#include "CButtonTopViewRight.h"

BEGIN_MESSAGE_MAP(CButtonTopViewRight, CWnd)
    ON_WM_PAINT()
    ON_WM_CREATE()
    ON_WM_MOUSEMOVE()
    ON_WM_LBUTTONUP( )
END_MESSAGE_MAP()

CButtonTopViewRight::CButtonTopViewRight(void)
{
	m_clrDefault = Color::LightGray;
	m_clrMouseMove = Color::DarkGray;
	m_bMouseMove = false;
}


CButtonTopViewRight::~CButtonTopViewRight(void)
{
	GdiplusShutdown(m_gdiplusToken);
}

/*****************************************************************************
* ++
* Method name   :    int CButtonTopViewRight::OnCreate(LPCREATESTRUCT lpCreateStruct)
* Description   :    On event Create handler. This function will be called
*	when the window is created
*
* Parameters    :  LPCREATESTRUCT lpCreateStruct (not use)
* Return values :    
* Mod. History  :    03/12/2012 - BaoTD1 (first created)
*                    
* --
*****************************************************************************/
int CButtonTopViewRight::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);

    return(0);
}

/*****************************************************************************
 * ++
 * Method name   :    void CButtonTopViewRight::OnPaint(void)
 * Description   :    On event Paint handler. This function will be called
 *	when the WM_PAIN is created
 *
 * Parameters    : 
 * Return values :    
 * Mod. History  :    03/12/2012 - BaoTD1 (first created)
 *					  08/06/2013 - NhatLD (remove unnecessary code)
 *
 * --
 *****************************************************************************/
void CButtonTopViewRight::OnPaint(void)
{
	CPaintDC dc(this); // Creates a device context for the client area, which
	// also erases the area to be drawn.
	CRect rect;
	GetClientRect(rect);

	HDC Memhdc;
	HBITMAP Membitmap;
	CRect MainRect(rect);

	// Double Buffer
	Memhdc = CreateCompatibleDC(dc.m_hDC);
	Membitmap = CreateCompatibleBitmap(dc.m_hDC, MainRect.Width() , MainRect.Height());
	SelectObject(Memhdc, Membitmap);

	CRect MemRect(0,0, MainRect.Width(), MainRect.Height());
	FillRect(Memhdc, MemRect, CreateSolidBrush(WHITE));
	Rectangle(Memhdc,MemRect.left, MemRect.top,MemRect.right, MemRect.bottom);
	// GDI+
	Graphics graphics(Memhdc);
	graphics.SetSmoothingMode(SmoothingModeHighQuality);

	Color colorTemp = m_clrDefault;
	if ( m_bMouseMove == TRUE )
	{
		colorTemp = 	m_clrMouseMove;
	}
	// Draw arrow right
	DrawArrow(&graphics, &rect, 3, colorTemp );
	//////////////--Mod NhatLD 8/6/2013 ////////////

	BitBlt(dc, MainRect.left, MainRect.top, MainRect.Width(), MainRect.Height(), Memhdc, 0, 0, SRCCOPY);
	DeleteObject(Membitmap);
	DeleteDC    (Memhdc);
	DeleteDC    (dc);
}

/******************************************************************************
* ++
* Method name   :    void CButtonTopViewRight::DrawBoard2D(Graphics* graphics)
* Description   :    Draw Board 2D.
*
* Parameters    :  "graphic"    [in,out] If non-null, the graphic.
* Return values :    true if it succeeds, false if it fails.
* 
* Mod. History  :    03/12/2012 - BaoTD1 (first created)
*
* --
*****************************************************************************/
BOOL CButtonTopViewRight::CreateRightButton( const RECT& rect, CWnd* pParentWnd)
{
	int nID = 0;
	///* Create window to draw board */
     if (!CWnd::Create(	NULL, 
						NULL, 
						WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW, 
						rect, 
						pParentWnd, nID, 
						NULL))
    {
		
        throw LPCSTR("CTopViewImageControl::Create window fail !");
        return (FALSE);
    }
	/*Invalidate();
	RedrawWindow();*/
	return TRUE;
}

/******************************************************************************
* ++
* Method name   :    void CButtonTopViewRight::DrawBoard2D(Graphics* graphics)
* Description   :    Draw Board 2D.
*
* Parameters    :  "graphic"    [in,out] If non-null, the graphic.
* Return values :    None
* 
* Mod. History  :    03/12/2012 - BaoTD1 (first created)
*
* --
*****************************************************************************/
void CButtonTopViewRight::OnMouseMove(UINT wParam, CPoint pos)
{
	SetCapture();               //  Capture the mouse input
	CRect wndRect;
//  GetWndRect(&wndRect);
	GetWindowRect(&wndRect);
	ScreenToClient(&wndRect);

	if (wndRect.PtInRect(pos))	
	{  
		m_bMouseMove = true;
	} 
	else
	{
		ReleaseCapture();
		m_bMouseMove = false;
	
	}
	this->Invalidate( 1 );
}

/******************************************************************************
* ++
* Method name   :    void CButtonTopViewRight::DrawArrow(Graphics* graphics)
* Description   :    Draw Button Left.
*
* Parameters    :    "graphic"    [in,out] If non-null, the graphic.
* Return values :    none
* 
* Mod. History  :    03/12/2012 - BaoTD1 (first created)
*					 08/06/2013 - NhatLD (remove unnecessary code)
*
* --
*****************************************************************************/
VOID CButtonTopViewRight::DrawArrow( Graphics* graphics , RECT* apRect, INT aiDirection, Color aColorArrow )
{
	
	SolidBrush ColorBrush(	aColorArrow );
	Gdiplus::Point arrPoint[3];
	arrPoint[0] = Gdiplus::Point(apRect -> right/2, apRect -> top + 20 );
	arrPoint[1] = Gdiplus::Point(apRect -> right/2, apRect -> bottom - 20);
	arrPoint[2] = Gdiplus::Point(apRect -> right -5, ( apRect -> top + apRect -> bottom ) / 2);
	
	graphics->FillPolygon(&ColorBrush, arrPoint,3); 
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  End Of File
//////////////////////////////////////////////////////////////////////////////////////////////////////////////